package com.sky.controller.user;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.mybatis.mp.core.mybatis.mapper.context.Pager;
import com.sky.context.BaseContext;
import com.sky.dto.ChangePasswordDTO;
import com.sky.dto.UserStatusDTO;
import com.sky.entity.UserBans;
import com.sky.result.Result;
import com.sky.service.UserService;
import com.sky.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 用户管理相关接口
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserManagementController {

    @Autowired
    private UserService userService;

    /**
     * 重置用户密码
     *
     * @param userId 用户ID
     * @return 新的默认密码
     */
    @PostMapping("/{userId}/reset-password")
    public Result<String> resetUserPassword(@PathVariable Integer userId) {
        log.info("重置用户密码，用户ID：{}", userId);
        String newPassword = userService.resetUserPassword(userId);
        return Result.success(newPassword);
    }

    /**
     * 修改密码
     *
     * @param changePasswordDTO 包含旧密码和新密码的DTO
     * @return 操作结果
     */
    @SaIgnore
    @PostMapping("/change-password")
    public Result changePassword(@RequestBody @Valid ChangePasswordDTO changePasswordDTO) {
        log.info("修改密码");
        Integer userId = Math.toIntExact(BaseContext.getCurrentId());
        userService.changePassword(userId, changePasswordDTO);
        return Result.success();
    }
} 